<?php
	function tpl_button_add( $title ){
		return '<button type="submit" class="x-button x-save">'.$title.'</button>';
	}

	function tpl_button_back( $title, $link ){
		return '<a class="x-button x-fresh" href="'.$link.'">'.$title.'</a>';
	}

	function tpl_button_close(){
		return '<a onclick="$(this).parent(\'.lightbox\').remove()" class="x-button x-fresh">Hủy bỏ</a>';
	}
	
	
	function tpl_input_code( $name, $value = '' ){
		return '<input type="text" value="'.$value.'" name="'.$name.'" class="x-text x-normal-text"/>';	
	}

	function tpl_input_phone( $name, $value = '' ){
		return '<input type="text" value="'.$value.'" name="'.$name.'" class="x-text" style="width:150px"/>';	
	}

	function tpl_input_fax( $name, $value = '' ){
		return '<input type="text" value="'.$value.'" name="'.$name.'" class="x-text" style="width:150px"/>';	
	}

	function tpl_input_price( $name, $value = '' ){
		return '<input type="text" value="'.$value.'" name="'.$name.'" class="x-text x-small-text" style="width:150px"/>';	
	}

	function tpl_input_persent( $name, $value = '' ){
		return '<input class="x-text x-status" type="text" name="'.$name.'" onclick="status_picker(this)" value="'.$value.'"/> %';	
	}

	function tpl_input_date( $name, $value = '' ){
		return '<input type="text" name="'.$name.'" value="'.show_date(DATE_FORMAT,$value).'" onclick="date_picker(this,{format: \'d/m/Y\' })" class="x-text x-date"/>';	
	}

	function tpl_input_address( $name, $value = '' ){
		return '<input type="text" value="'.$value.'" name="'.$name.'" class="x-text" style="width:400px"/>';	
	}

	function tpl_input_url( $name, $value = '' ){
		return '<input type="text" value="'.$value.'" name="'.$name.'" class="x-text" style="width:400px"/>';	
	}
	
	function tpl_input_normal( $name, $value = '' ){
		return '<input type="text" value="'.$value.'" name="'.$name.'" class="x-text x-normal-text"/>';	
	}
	
	function tpl_input_big( $name, $value = '' ){
		return '<input type="text" value="'.$value.'" name="'.$name.'" class="x-text x-big-text"/>';	
	}
	
	function tpl_input_small( $name, $value = '' ){
		return '<input type="text" value="'.$value.'" name="'.$name.'" class="x-text x-small-text"/>';	
	}
	
	function tpl_select( $name, $field_id, $field_label, $data, $selected = NULL ){
		$str = '<select class="x-select" name="'.$name.'">';	
		foreach( $data as $a ){
			$str .= '<option value="'.$a[$field_id].'"'.( $selected !=NULL && $selected == $a[$field_id] ?' selected' :'').'>'.$a[$field_label].'</option>';
		}	
		$str .='</select>';
		return $str;
	}
	
	
	function tpl_checkbox( $name, $value, $checked = false, $label = NULL ){
		$checked = $checked ? ' checked' : '';
		if( $label == NULL ){
			return '<input type="checkbox" value="'.$value.'" name="'.$name.'"'.$checked.'/>';
		}
		
		return '<label>
			<input type="checkbox" value="'.$value.'" name="'.$name.'"'.$checked.'/>
			'.$label.'
		</label>';
	}
	
	function tpl_checkbox_item( $id ){
		return '<input name="ID[]" value="'.$id.'" type="checkbox" class="x-checkbox x-checkall" on="$(this).each(function(){ if( this.checked ) $(this.parentNode.parentNode).addClass(\'row-select\'); else $(this.parentNode.parentNode).removeClass(\'row-select\'); })"/>';
	}
	
	
	
	function tpl_search_form($link_form, $link_adv){
		return '<div class="x-pop">
			<form action="'.$link_form.'" onsubmit="return ajax_form(this,true)" method="post">
			<div class="simple-search">
				<a href="'.$link_adv.'" title="Tìm kiếm nâng cao" class="adv-search"></a>
				<input type="text" name="s" value="'. htmlentities( stripslashes(get('s')) , ENT_QUOTES, "UTF-8").'" class="s" autocomplete="off" spellcheck="false" placeholder="Tìm kiếm"/>
			</div>
			</form>
		</div>';
	}
	
		
	function tpl_search_select( $name, $field_id, $field_label, $data ){
		$str = '<div class="search-select">';	
		foreach( $data as $a ){
			$str .= '<label><input type="checkbox" name="'.$name.'" value="'.$a[$field_id].'"/>'.$a[$field_label].'</label>';
		}	
		$str .='</div>';
		return $str;
	}	
	
	/*
		Auto
	*/
	function tpl_select_users( $name, $title='', $users = array() ){
		$s = '<div class="x-select-users" x-name="'.$name.'" x-title="'.$title.'">';
		foreach( $users as $u ){
			$s.='<span class="item">
				<input type="hidden" name="'.$name.'" value="'.$u['ID'].'">'.get_user_link($u).' <span class="x" onclick="$(this.parentNode).remove()"></span>
			</span>';
		}
		$s.='</div>';
		return $s;
	}

	function tpl_select_user( $name, $title='', $user = NULL ){
		$s = '<div class="x-select-user" x-name="'.$name.'" x-title="'.$title.'">';
		if($user){
			$s.='<span class="item">
				<input type="hidden" name="'.$name.'" value="'.$user['ID'].'">'.get_user_link($user).' <span class="x" onclick="$(this.parentNode).remove()"></span>
			</span>';
		}	
		$s.='</div>';
		return $s;
	}	

	function tpl_auto_select($options){
		$title = $options['title'];
		$link  = $options['link'];
		
		$s='<div class="x-auto" '.$options['style'].' onclick="this.getElementsByTagName(\'input\')[0].focus()">';
		if( $options['items'] ){
			foreach( $options['items'] as $a ){
				if(!$a) continue;
				$s.='<div class="x-auto-current">';
				$s.='<input type="hidden" name="'.$options['name'].'" value="'.$a['ID'].'"/>';
				$s.='<a class="l" target="_blank" href="'.$link.$a['ID'].'">'.$a[$title].'</a>';						
				$s.='<a class="x" onclick="Owl(this).parent(\'.x-auto-current\').remove();return false"></a>';
				$s.='</div>';	
			}
		}	
		$s.='<input type="text" valid="[{type: \''.$options['type'].'\', url: \''.$options['url'].'\', data: { name: \''.$options['name'].'\', link: \''.$link.'\' , title: \''.$title.'\'} }]"/>';
		$s.='</div><span class="x-auto-icon"></span>';					
		return $s;
	}	


	
?>